package mrusanov.experience

import mrusanov.player.{Player, Talent}


// TODO use BigDecimal instead of int to handle decimal values
class Experienced(private var _experience:BigDecimal, val talent:Talent) {
  def level = LevelSystem.level(experience.toInt)

  def experience = _experience
  def experience_=(value:BigDecimal) {
    require(value > experience, "Experience cann't be subtracted")

    val added = value - experience
    if (!this.isInstanceOf[Player]) {
      _experience += added + (added * talent.bonusMultiplier)
    } else {
      val player = asInstanceOf[Player]
      val bonus = player.team.flatMap(_.coach).map(_.expBonus(added)).getOrElse(BigDecimal(0))
      _experience += added + (added * talent.bonusMultiplier) + bonus
    }
  }

  def fairSalary = experience / 10
}
